function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function showUpdateInterval()
{
  var rl = document.getElementById("dispUpdate");
  rl.innerHTML = "";
  if (updateInterval != null)
  {
	rl.innerHTML = rl.innerHTML + "<a href=\"javascript:setUpdateInterval(-1);\">No refresh</a>, ";
  }
  else 
  {
    rl.innerHTML += "No refresh, "
  }

  if (updateInterval != "15")
  {
	rl.innerHTML += "<a href=\"javascript:setUpdateInterval(15);\">Update every 15s</a>, ";
  }
  else
  {
	rl.innerHTML += "Update every 15s, ";
  }
	
   if (updateInterval != "60")
   {
 	rl.innerHTML += "<a href=\"javascript:setUpdateInterval(60);\">Update every minute</a>";
   }
   else 
   {
	rl.innerHTML += "Update every minute";
   }
}

function setUpdateInterval(interval)
{
	if (interval == -1)
	{
   		eraseCookie("updateInterval");
		updateInterval = null;
  		if (timeoutVar != null)
			clearTimeout(timeoutVar);
	}
	else 
	{
		createCookie("updateInterval",interval,30);
		updateInterval = interval + "";
		timeoutVar = setTimeout(function () { document.location.href=document.location.href;},interval*1000);
	}
	
	showUpdateInterval();

}

